package com.wlts.wzy.DYGoodsModule.controller;

import com.wlts.wzy.Base.BasePageParam;
import com.wlts.wzy.DYGoodsModule.DYapi.DyApiClient;
import com.wlts.wzy.DYGoodsModule.DYapi.DySdk;
import com.wlts.wzy.DYUserModule.entity.DyOauth;
import com.wlts.wzy.DYUserModule.entity.DyStoreUser;
import com.wlts.wzy.Result.Result;
import com.wlts.wzy.api.response.dy.DyFreightTemplateResponse;
import com.wlts.wzy.configBean.DyConfig.DyConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 快手商品类目表 前端控制器
 * </p>
 *
 * @author zhiyong
 * @since 2021-01-31
 */
@Api(tags = "抖音运费模板 前端控制器")
@RestController
@RequestMapping("/DYGoodsModule/DyExpressTemplate")
public class DyExpressTemplateListController {
    @Autowired
    private DyConfig dyConfig;

    @ApiModelProperty("分页抖音运费模板")
    @RequestMapping(value = "getDyTemplate", method = RequestMethod.POST)
    public Result<DyFreightTemplateResponse> getDyTemplate(@RequestBody BasePageParam page){

        DyStoreUser dyStoreUser = dyConfig.getDyStoreUserConfig();

        DyOauth dyOauth = dyStoreUser.getDyOauth();

        if (dyOauth == null) {
            return Result.buildResult(500,"账号未授权");
        }

        DyFreightTemplateResponse response = DySdk.getfreightTemplateList(dyStoreUser.getAppKey(),dyStoreUser.getAppSecret(),dyOauth.getAccessToken(),page.getCurrentPage()-1,page.getPageSize(),null);

        return Result.buildResult(response);
    }

}